/**
 *  *2010-9-5 下午02:34:05  add 
 */
package com.base.myproject.client.busi.service;

import com.base.myproject.client.busi.ccode.CcodeChangePass;
import com.base.myproject.client.busi.ccode.DeleteCcode_s;
import com.base.myproject.client.busi.ccode.EditorCcode_service;
import com.base.myproject.client.busi.ccode.NewCCode;
import com.base.myproject.client.busi.ccode.ResetCcodePass;
import com.base.myproject.client.system.BaseResource;
import com.base.myproject.client.ui.BaseOpenJSP;
import com.base.myproject.client.ui.BaseTabPanel;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PushButton;

/**
 * @author Administrator
 *2010-9-5
 * javazgw@gmail.com
 */
public class CcodeMain extends LayoutContainer{
	 PushButton a1;
	 PushButton a2;
	 PushButton a3;
	 PushButton a4;
	 PushButton a5;
	 PushButton a6;
	 PushButton a7;
	 PushButton a8;
	 PushButton a9;
	public CcodeMain()
	{
		super();
		init();
	}
	void init()
	{
		
		
	}
	 protected void onRender(Element parent, int index) {  
		
	
		 super.onRender(parent, index);  
		 this.setMonitorWindowResize(true);
//		 this.setLayout(new CenterLayout() );
		
		 LayoutContainer panel = new LayoutContainer();
		 TableLayout tl = new TableLayout(2);
			TableData td = new TableData();
			td.setRowspan(1);
			td.setColspan(1);
			td.setPadding(10);
			td.setHorizontalAlign(HorizontalAlignment.LEFT);
			td.setVerticalAlign(VerticalAlignment.TOP);
			
			
			panel.setLayout(tl);
//			  a1 = new PushButton(
//				        new Image(BaseResource.INSTANCE.adduser64()));
			CcodeItem codeitem1 = new CcodeItem(a1,"添加新会员。");
			
			//  a2 = new PushButton(
			//	        new Image(BaseResource.INSTANCE.edit_info64()));
			CcodeItem codeitem2 = new CcodeItem(a2,"修改会员。");
			
			
//			  a3 = new PushButton(
//				        new Image(BaseResource.INSTANCE.remove_user64()));
			CcodeItem codeitem3 = new CcodeItem(a3,"删除会员。需要密码");
			
			
//			  a4 = new PushButton(
//				        new Image(BaseResource.INSTANCE.user_info64()));
			CcodeItem codeitem4 = new CcodeItem(a4,"查看会员信息。");
		
			
//			  a5 = new PushButton(
//				        new Image(BaseResource.INSTANCE.finance64()));
			CcodeItem codeitem5 = new CcodeItem(a5,"会员充值。");
//		
//			  a6 = new PushButton(
//				        new Image(BaseResource.INSTANCE.switchuser64()));
			CcodeItem codeitem6 = new CcodeItem(a6,"积分转换。");
			
//			  a7 = new PushButton(
//				        new Image(BaseResource.INSTANCE.downloaduserinfo64()));
			CcodeItem codeitem7 = new CcodeItem(a7,"下载会员资料。需要密码");
			
//			a8 = new PushButton(
//				        new Image(BaseResource.INSTANCE.resetpassword64()));
			CcodeItem codeitem8 = new CcodeItem(a8,"重置会员密码。");
			
//			a9 = new PushButton(
//			        new Image(BaseResource.INSTANCE.changepassword64()));
			CcodeItem codeitem9 = new CcodeItem(a9,"修改会员密码。");
		
			
			panel.add(codeitem1,td);
			panel.add(codeitem2,td);
			panel.add(codeitem3,td);
			panel.add(codeitem4,td);
			panel.add(codeitem5,td);
			panel.add(codeitem6,td);
			panel.add(codeitem7,td);
			panel.add(codeitem8,td);
			panel.add(codeitem9,td);
			a1.addClickHandler(getClickHandler());
			a2.addClickHandler(getClickHandler());
			a3.addClickHandler(getClickHandler());
			a4.addClickHandler(getClickHandler());
			a5.addClickHandler(getClickHandler());
			a6.addClickHandler(getClickHandler());
			a7.addClickHandler(getClickHandler());
			a8.addClickHandler(getClickHandler());
			a9.addClickHandler(getClickHandler());
//			panel.add(codeitem5,td);
//			panel.setAutoHeight(true);
//			Tools.setResize(panel,1,1);
			
			this.add(panel);
			this.layout(true);
	 }
	 private ClickHandler getClickHandler()
		{
			ClickHandler clickhandler = new ClickHandler()
			{

				@Override
				public void onClick(ClickEvent event) {
					if(event.getSource().equals(a1))
					{
						 NewCCode newccode = new NewCCode();
						 newccode.show();
					}
					else if(event.getSource().equals(a2))
					{
						
						(new EditorCcode_service()).show();
					}
					else if(event.getSource().equals(a3))
					{
						(new DeleteCcode_s()).show();
					}
					else if(event.getSource().equals(a4))
					{
						String  command= "BaseOpenJSP?busijsp/ccode/ccodefinaceX.jsp";
						int index = command.indexOf("?");
						
						String jsp = command.substring(index+1);
						
						BaseOpenJSP w = new BaseOpenJSP(jsp);
						w.complete();
						
						BaseTabPanel.getInstance().addTab("会员信息查询", w);
					}
					else if(event.getSource().equals(a5))
					{
						new AddFinace_acc().showDialog();
					}
					else if(event.getSource().equals(a6))
					{
						
					}
					else if(event.getSource().equals(a7))
					{
						
					}
					else if(event.getSource().equals(a8))
					{
						ResetCcodePass d = new ResetCcodePass();
						 d.showDialog();
					}
					else if(event.getSource().equals(a9))
					{

						 CcodeChangePass c = new CcodeChangePass(null);
						 c.showDialog();
					}
					
				}
			};
			return clickhandler;
		}
	 
	 private  class CcodeItem extends LayoutContainer
	 {
		 HTML html = new HTML();
		 
		 PushButton a1 ;
		 String htmlname ;
	 	 public CcodeItem(PushButton a1 ,String htmlname)
	 	 {
	 		this.a1 = a1;
	 		this.htmlname = htmlname;
	 		
	 	 }
	 	protected void onRender(Element parent, int index) {  
	 		super.onRender(parent, index);
	 		HorizontalPanel lc = new HorizontalPanel();
	 		html.setHTML("<p style='white-space:normal; display:block;width:360px; word-break:break-all;margin-left: 10px'>&nbsp;&nbsp;"+htmlname+"</p>");
	 		
	 		//HTML h = new HTML();
	 		//h.setHTML(html)
	 		
	 		lc.add(a1);
	 		lc.add(html);
	 		lc.setVerticalAlign(VerticalAlignment.TOP);
	 		
	 		lc.setWidth("420px");
	 		
	 		this.add(lc);
	 		
	 	}
	 	public PushButton getButton()
	 	{
	 		return a1;
	 	}
	 }
}
